//
//  NSString+GPRegex.m
//  YueYue
//
//  Created by LiuYu on 2024/10/24.
//

#import "NSString+GPRegex.h"

@implementation NSString (GPRegex)
- (BOOL)containsChinese
{
    NSError *error = nil;
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[\\u4e00-\\u9fa5]" options:0 error:&error];
    if (error) {
        NSLog(@"正则表达式错误：%@", error);
        return NO;
    }
    NSRange range = [regex rangeOfFirstMatchInString:self options:0 range:NSMakeRange(0, [self length])];
    return range.location != NSNotFound;
}

- (BOOL)containsEmoticon
{
    NSError *error = nil;
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\[[^\\[\\]]+\\]" options:0 error:&error];
    if (error) {
        NSLog(@"正则表达式错误：%@", error);
        return NO;
    }
    NSRange range = [regex rangeOfFirstMatchInString:self options:0 range:NSMakeRange(0, [self length])];
    return range.location != NSNotFound;
}

- (BOOL)containsNonChineseLanguageText
{
    NSString *pattern = @"[^\\p{Script=Han}\\d\\p{P}\\p{Z}]";
        NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:nil];
        
        NSRange range = [regex rangeOfFirstMatchInString:self options:0 range:NSMakeRange(0, self.length)];
        return range.location != NSNotFound;
}
@end
